package com.example.demo.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class ServiceHandler implements InvocationHandler {
    private Object target;

    public ServiceHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //类似AOP pointcut切点的操作
        if ("sayHello".equals(method.getName())) {
            System.out.println("before invoke");
        }
        return method.invoke(target, args);
    }
}
